<template>
  <div id="common-table">
    <el-table :data="tableData" height="578" stripe>
      <el-table-column
        show-overflow-tootip
        v-for="(item) in tableLabel"
        :key="item.prop"
        :label="item.label"
        :width="item.width ? item.width : 125"
      >
        <template slot-scope="scope">
          <span style="margin-left: 10px">{{scope.row[item.prop]}}</span>
        </template>
      </el-table-column>
      <el-table-column v-if="isToolShow" label="操作" min-width="180">
        <template slot-scope="scope">
          <el-button size="mini" class="edit" @click="hadleEdit(scope.row)">编辑</el-button>
          <el-button size="mini" class="delete" type="danger" @click="handleDelete(scope.row)">删除</el-button>
        </template>
      </el-table-column>
      <el-table-column></el-table-column>
    </el-table>
    <div class="pager-wrapper">
      <el-pagination
        class="pager"
        layout="prev, pager, next"
        :total="config.total"
        :current-page.sync="config.page"
        @current-change="changePage"
        :page-size="20"
      >
      </el-pagination>
    </div>
  </div>
</template>

<script>
export default {
  name: 'CommonTable',
  props: {
    tableData: Array,
    tableLabel: Array,
    config: Object,
    isToolShow: {
      type: Boolean,
      default: true
    }
  },
  methods: {
    hadleEdit(row) {
      let newRow = Object.assign({}, row)
      this.$emit('edit', newRow)
    },
    handleDelete(row) {
      this.$emit('del', row)
    },
    changePage(page) {
      this.$emit('changePage', page)
    }
  }
}
</script>

<style lang="less" scoped>
#common-table {
  background-color: #fff;
  position: relative;
  .pager-wrapper {
    background-color: #fff;
    display: flex;
    justify-content: flex-end;

  }
}
</style>